Skip to content

feat: MCP gateway — govern tools/call (step 9) - #7

Merged
prashar32 merged 1 commit into
mainfrom
feat/step-9-mcp-gateway
May 30, 2026
Merged

feat: MCP gateway — govern tools/call (step 9)#7
prashar32 merged 1 commit into
mainfrom
feat/step-9-mcp-gateway

Conversation

@prashar32

Copy link
Copy Markdown
Owner

What & why

Implements the MCP gateway (§8 step 9): a JSON-RPC reverse proxy at POST /mcp in front of an upstream MCP server. Point your MCP client at the gateway and governance is invisible to allowed, approved calls.

It forwards every MCP method transparently and intercepts tools/call:

  • Per-tool allowlist (exact name or glob) — disallowed tools never reach upstream (-32001).
  • Read-only vs side-effecting classification (config read-only set) — only side-effecting tools are gated.
  • Approval gate for side-effecting tools — blocks until a human resolves (bounded by RISKKERNEL_MCP_APPROVAL_TIMEOUT); denied/timed-out calls never reach upstream.
  • Audit — every governed call recorded to tool_calls.
  • Attribution via X-RiskKernel-Run-Id.

This is the approval gate's natural live producer (step 7), reusing the gate, manager, and storage. Enabled only when RISKKERNEL_MCP_UPSTREAM is set.

Verification

  • go test -race ./... green; vet + gofmt clean.
  • Gateway tests vs a fake upstream: non-tool passthrough, allowlist block, read-only forward, approve→forward, deny→error (upstream untouched on both reject paths).
  • Live end-to-end: daemon + a fake upstream MCP server; a read-only tools/call forwards and returns the upstream result.

Notes

/mcp is JSON-RPC (not REST), so it's documented in CHANGELOG/.env.example rather than the /v1 OpenAPI surface.

A JSON-RPC reverse proxy at POST /mcp in front of an upstream MCP server. It
forwards every MCP method transparently and intercepts tools/call:

- per-tool allowlist (exact name or glob) — disallowed tools never reach
  upstream (JSON-RPC error -32001);
- read-only vs side-effecting classification (config read-only set); only
  side-effecting tools are gated;
- side-effecting tools route through the deterministic approval gate (blocks
  until a human resolves, bounded by RISKKERNEL_MCP_APPROVAL_TIMEOUT) — denied
  or timed-out calls never reach upstream;
- every governed call recorded to the tool_calls audit table;
- attribution by X-RiskKernel-Run-Id (same as the proxy).

This is the approval gate's natural live producer (step 7). Enabled only when
RISKKERNEL_MCP_UPSTREAM is set; allowlist/read-only via RISKKERNEL_MCP_*.

Tests vs a fake upstream: passthrough of non-tool methods, allowlist block,
read-only forward, approve->forward, deny->error (upstream untouched in both
reject paths). Verified live end-to-end.
@prashar32
prashar32 merged commit 045c9cb into main May 30, 2026
3 checks passed
@prashar32
prashar32 deleted the feat/step-9-mcp-gateway branch May 30, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant